//
// Created by calm on 2023-12-27.
//
#include "stdio.h"
/*
 <return type> <fun_name> (<args>){
    statement;
    <return value>;
 }
 */
//声明一个函数(函数原型)
//int add(int x,int y);

//函数的实现
int add(int x,int y){
    return x+y;
}

//可变长参数
int fun01(void){
    printf("fun01 executing\n");
}


//递归
//费氏数列  1，1，2，3，5，8  f(n)=f(n-1)+f(n-2);(n>2,f(1)=1,f(2)=1)
unsigned long fei(unsigned long n){
    if(n==1|| n==2){
        return 1;
    }
    return fei(n-1)+fei(n-2);
}
//f(n)=f(n-1)+f(n-2);(n>2,f(1)=1,f(2)=1)
unsigned long fei2(unsigned long n){
    if(n==1 || n==2){
        return 1;
    }
    long last = 0;
    long current= 1;
    for (int i=0;i<=n-2;i++){
     int temp=current;
     current+=last;
     last= temp;
    }
    return current;
}

int main(){

//    fun01(1);
//    fun01(1,2,3);
    int result1 =fei2(50);
    printf("%5d",result1);

int result2 =fei(20);
printf("%5d",result2);
    return -1;
}

